.class public Lcom/glympse/platform/common/DownloadAvatarJob;
.super Lcom/glympse/platform/common/HttpJob;
.source "DownloadAvatarJob.java"


# instance fields
.field private m_nAvatarVersion:I

.field private m_oUser:Lcom/glympse/platform/common/User;

.field private m_strAgent:Ljava/lang/String;

.field private m_strSession:Ljava/lang/String;


# direct methods
.method public constructor <init>(Lcom/glympse/platform/common/User;)V
    .locals 6
    .parameter "oUser"

    .prologue
    .line 29
    invoke-direct {p0}, Lcom/glympse/platform/common/HttpJob;-><init>()V

    .line 23
    const/4 v2, 0x0

    iput-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_oUser:Lcom/glympse/platform/common/User;

    .line 24
    const/4 v2, 0x0

    iput v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_nAvatarVersion:I

    .line 25
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    invoke-virtual {v2}, Lcom/glympse/platform/Platform;->GetBrowserAgent()Ljava/lang/String;

    move-result-object v2

    iput-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strAgent:Ljava/lang/String;

    .line 26
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    iget-object v2, v2, Lcom/glympse/platform/Platform;->m_oServerPost:Lcom/glympse/platform/common/ServerPost;

    iget-object v2, v2, Lcom/glympse/platform/common/ServerPost;->m_strSession:Ljava/lang/String;

    iput-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strSession:Ljava/lang/String;

    .line 34
    iput-object p1, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_oUser:Lcom/glympse/platform/common/User;

    .line 35
    iget v2, p1, Lcom/glympse/platform/common/User;->m_nAvatarVersion:I

    iput v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_nAvatarVersion:I

    .line 38
    const/4 v2, 0x1

    iput-boolean v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_fCompleteOnMainThread:Z

    .line 41
    new-instance v2, Ljava/lang/StringBuilder;

    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v3

    iget-object v3, v3, Lcom/glympse/platform/Platform;->m_oServerPost:Lcom/glympse/platform/common/ServerPost;

    invoke-virtual {v3}, Lcom/glympse/platform/common/ServerPost;->GetSessionUrl()Ljava/lang/String;

    move-result-object v3

    invoke-static {v3}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v3, "users/"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    iget-object v3, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_oUser:Lcom/glympse/platform/common/User;

    iget-wide v3, v3, Lcom/glympse/platform/common/User;->m_lUserId:J

    invoke-static {v3, v4}, Lcom/glympse/platform/common/Helpers;->UserIdToStr(J)Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    const-string v3, "/picture?v="

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    iget v3, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_nAvatarVersion:I

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    iput-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strUrl:Ljava/lang/String;

    .line 47
    iget-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_oUser:Lcom/glympse/platform/common/User;

    invoke-virtual {v2}, Lcom/glympse/platform/common/User;->SortTickets()V

    .line 48
    iget-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_oUser:Lcom/glympse/platform/common/User;

    iget-object v2, v2, Lcom/glympse/platform/common/User;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    invoke-virtual {v2}, Lcom/glympse/platform/GVector$Tickets;->elements()Ljava/util/Enumeration;

    move-result-object v0

    .local v0, iter:Ljava/util/Enumeration;
    :cond_0
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v2

    if-nez v2, :cond_1

    .line 59
    :goto_0
    return-void

    .line 50
    :cond_1
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/glympse/platform/common/Ticket;

    .line 53
    .local v1, oCur:Lcom/glympse/platform/common/Ticket;
    const-wide/16 v2, 0x0

    iget-wide v4, v1, Lcom/glympse/platform/common/Ticket;->m_lTicketId:J

    cmp-long v2, v2, v4

    if-eqz v2, :cond_0

    .line 55
    iget-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strUrl:Ljava/lang/String;

    new-instance v3, Ljava/lang/StringBuilder;

    invoke-static {v2}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v3, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v2, "&t="

    invoke-virtual {v3, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    iget-wide v3, v1, Lcom/glympse/platform/common/Ticket;->m_lTicketId:J

    invoke-static {v3, v4}, Lcom/glympse/platform/common/Helpers;->LongToBase32(J)Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    iput-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strUrl:Ljava/lang/String;

    goto :goto_0
.end method


# virtual methods
.method public AddRequestHeaders(Lcom/glympse/platform/GHttpConnection;)V
    .locals 3
    .parameter "oHttpConn"

    .prologue
    .line 67
    :try_start_0
    const-string v1, "User-Agent"

    iget-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strAgent:Ljava/lang/String;

    invoke-virtual {p1, v1, v2}, Lcom/glympse/platform/GHttpConnection;->SetRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 68
    iget-object v1, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strSession:Ljava/lang/String;

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_0

    .line 70
    const-string v1, "GLYMPSE_Session"

    iget-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strSession:Ljava/lang/String;

    invoke-virtual {p1, v1, v2}, Lcom/glympse/platform/GHttpConnection;->SetRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 73
    :cond_0
    new-instance v1, Ljava/lang/StringBuilder;

    const-string v2, "DownloadAvatarJob - Session:"

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    iget-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strSession:Ljava/lang/String;

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    const-string v2, ", URL:"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    iget-object v2, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_strUrl:Ljava/lang/String;

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 79
    :goto_0
    return-void

    .line 75
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 77
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0
.end method

.method public OnComplete(Lcom/glympse/platform/common/JobQueue;)V
    .locals 6
    .parameter "oJobQueue"

    .prologue
    .line 85
    iget-object v3, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_abResponse:[B

    if-eqz v3, :cond_0

    iget-object v3, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_abResponse:[B

    array-length v3, v3

    if-lez v3, :cond_0

    .line 88
    const/4 v1, 0x0

    .line 91
    .local v1, oImage:Lcom/glympse/platform/GImage;
    :try_start_0
    new-instance v2, Lcom/glympse/platform/GImage;

    iget-object v3, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_abResponse:[B

    const/4 v4, 0x0

    const/4 v5, 0x1

    invoke-direct {v2, v3, v4, v5}, Lcom/glympse/platform/GImage;-><init>([BZZ)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .end local v1           #oImage:Lcom/glympse/platform/GImage;
    .local v2, oImage:Lcom/glympse/platform/GImage;
    move-object v1, v2

    .line 99
    .end local v2           #oImage:Lcom/glympse/platform/GImage;
    .restart local v1       #oImage:Lcom/glympse/platform/GImage;
    :goto_0
    if-eqz v1, :cond_0

    .line 102
    iget-object v3, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_oUser:Lcom/glympse/platform/common/User;

    iput-object v1, v3, Lcom/glympse/platform/common/User;->m_oImageAvatar:Lcom/glympse/platform/GImage;

    .line 103
    iget-object v3, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_oUser:Lcom/glympse/platform/common/User;

    iget v4, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_nAvatarVersion:I

    iput v4, v3, Lcom/glympse/platform/common/User;->m_nAvatarVersionLocal:I

    .line 104
    iget-object v3, p0, Lcom/glympse/platform/common/DownloadAvatarJob;->m_oUser:Lcom/glympse/platform/common/User;

    invoke-virtual {v3}, Lcom/glympse/platform/common/User;->clearAvatarScaleCache()V

    .line 107
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v3

    const/16 v4, 0x2000

    invoke-virtual {v3, v4}, Lcom/glympse/platform/Platform;->DoUpdate(I)V

    .line 110
    .end local v1           #oImage:Lcom/glympse/platform/GImage;
    :cond_0
    return-void

    .line 93
    .restart local v1       #oImage:Lcom/glympse/platform/GImage;
    :catch_0
    move-exception v3

    move-object v0, v3

    .line 95
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0
.end method
